package com.archgeek.java.conc.future;

import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 *
 * 直接创建异步任务
 *
 * @author pizhihui
 * @date 2024-03-08 10:36
 */
public class Demo2 {
    public static void main(String[] args) {

        CompletableFuture future = new CompletableFuture();
        System.out.println(future.isDone());

        CompletableFuture cf1 = CompletableFuture.runAsync(new Runnable() {
            @Override
            public void run() {
                CFutureTools.doRandomTask("runAsync任务");
            }
        });




        cf1.thenCompose(new Function() {
            @Override
            public Object apply(Object o) {

                return CompletableFuture.runAsync(() -> {

                });
            }
        });


        CompletableFuture cf2 = CompletableFuture.supplyAsync(new Supplier<String>() {
            @Override
            public String get() {
                CFutureTools.doRandomTask("supplyAsync任务");
                return null;
            }
        });

        System.out.println("end....");
        future.join();



    }

}
